/**
 * $dialog 获取当前弹框
 */
import {
  findComponentsDownward
} from '@admin/utils/index'
let currentDialog = null
export default {
  // 设置cd
  _setCurrentDialog() {
    const rootVm = document.querySelector('#app').__vue__
    const dialogVms = findComponentsDownward(rootVm, 'ElDialog') || []
    if (dialogVms.length) {
      const topDialog = Array.from(dialogVms).sort((a, b) => {
        return Number(b.$el.style.zIndex) - Number(a.$el.style.zIndex)
      })
      currentDialog = topDialog[0]
    } else {
      currentDialog = null
    }
  },
  close() {
    currentDialog && currentDialog.handleClose()
  }
}
